package com.honeycomb.article.dto;

import java.util.Arrays;


public enum MessageType {
	MAIN(0, "主题文章"),
	TOP(1, "置顶文章"),
	NORMAL(2, "");
	
	private int intValue;
	private String showString;
	
	private MessageType(int intValue, String showString) {
		this.intValue = intValue;
		this.showString = showString;
	}
	
	/**
	 * 根据传入字符串来返回对应的状态类型
	 */
	public static MessageType getMessageType(String strValue) {
		try {
			MessageType type = valueOf(strValue);
			return type;
		}
		catch(Exception ex) {
			throw new IllegalArgumentException("Value '" + strValue + "' is not allowed in MessageType. Only "
					+ Arrays.toString(MessageType.values()) + " are allowed."
					);
		}
	}
	
	/**
	 * 根据传入INT值来返回对应的状态类型
	 */
	public static MessageType getMessageType(int intValue) {
		for (MessageType elem : MessageType.values()) {
			if (elem.toIntValue() == intValue) {
				return elem;
			}
		}

		throw new IllegalArgumentException("Value '" + intValue
				+ "' is not allowed in MessageType.");
	}

	/**
	 * 返回int值类型。
	 * @return
	 */
	public int toIntValue() {
		return intValue;
	}

	public String toShowString() {
		return showString;
	}
	
}

